<?php

class WeiBo {
	private $message = "";
    function WeiBo() {

    }
    
    public function run() {
    	include( ROOT_PATH.'include/weibo/config.php' );
		include( ROOT_PATH.'include/weibo/saetv2.ex.class.php' );
    	$sql = "select * from td_my_param where `key`='weibotoken' and `qq`='1004634672' ";
		$ret = DB::GetQueryResult($sql,true);
		$tok = json_decode($ret['value']);
		$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $tok->access_token );
    	$uid_get = $c->get_uid();
		$uid = $uid_get['uid'];
		$p = '/@([\S]+)\s+(.*)/';
		preg_match($p, trim($_POST[Message]), $m);
		if($m[1]=="weibo") {
			$ret = $c->update($m[2] );	//发送微博
			if ( isset($ret['error_code']) && $ret['error_code'] > 0 ) {
				$this->message =  "发送失败，错误：{$ret['error_code']}:{$ret['error']}";
			} else {
				$this->message =  "发送成功";
			}
		} else if("关注"==$m[1]) {
			$ret = $c->follow_by_name( $m[2] );
			print_r($ret);
		}
    }
    
    private function __get($property_name) {
		return $this-> $property_name;
	}

	private function __set($property_name, $value) {
		$this->$property_name = $value;
	}
}
?>